Skip to content

fix(integrations): Cache missing GitHub repo tree lookups#113113

Open
armenzg wants to merge 4 commits intomasterfrom
more_endpoints
Open

fix(integrations): Cache missing GitHub repo tree lookups#113113
armenzg wants to merge 4 commits intomasterfrom
more_endpoints

Conversation

@armenzg
Copy link
Copy Markdown
Member

@armenzg armenzg commented Apr 15, 2026

Cache missing GitHub repo tree lookups as empty results and keep them in cache.

Auto source code config was repeatedly requesting missing repos/refs and creating
high-volume 404 failures. This changes repo tree fetching to treat not-found outcomes
as empty results, cache them, and return empty RepoTree entries instead of dropping
those repositories.

Cache expiry remains staggered using shifted_seconds so empty-cache refreshes do not
thunder at the same time across many repositories.

I considered keeping 404 behavior separate from 409 handling, but using one empty-result
cache path makes behavior and expiry consistent for both outcomes while preserving normal
error raising for non-not-found API failures.

Tests add coverage for 404 caching, staggered TTL behavior, and non-404 error handling,
and update GitHub integration expectations now that 404 repos are represented as empty
trees.

Fixes SENTRY-5K7G

Cache GitHub repo tree 404 responses as empty results to avoid repeated
failing requests from auto source code config. Keep non-404 API errors
raising normally and cover both behaviors with tests.

Fixes SENTRY-5K7G
Co-Authored-By: Codex <[email protected]>

Made-with: Cursor
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 15, 2026
cursor[bot]

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

armenzg added 3 commits April 16, 2026 08:09
Apply shifted cache expiry to not-found repo tree responses so negative
cache entries do not expire simultaneously across repositories.

Refs SENTRY-5K7G
Co-Authored-By: Codex <[email protected]>

Made-with: Cursor
Apply a single empty-result cache path for repo tree fetches so 409 and
404 outcomes are both cached with staggered expiry. Update GitHub
integration tests to expect 404 repos as empty trees.

Fixes SENTRY-5K7G
Co-Authored-By: Codex <[email protected]>

Made-with: Cursor
Switch patch targets to the imported GitHubBaseClient symbol so mypy
passes when github integration tests are part of the push hooks.

Refs SENTRY-5K7G
Co-Authored-By: Codex <[email protected]>

Made-with: Cursor

repo_full_name: e.g. getsentry/sentry
tree_sha: A branch or a commit sha
shifted_seconds: Staggers cache expiration times across repositories
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller makes the cache expire around 24 hour buckets (per repo) so it doesn't all expire around the same hour window.

# being acceptable to sometimes not having everything cached
cache.set(key, repo_files, self.CACHE_SECONDS + shifted_seconds)
else:
cache.set(key, [], self.CACHE_SECONDS + shifted_seconds)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty list as a negative cache.



def _is_not_found_error(error: ApiError) -> bool:
if error.code == 404:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all honestly, it is likely the 404 is real and even if we only fetch once a day we would still get a 404 but who knows maybe GitHub may send the wrong status code.

)

with patch.object(sentry.integrations.github.client.GitHubBaseClient, "page_size", 1):
with patch.object(GitHubBaseClient, "page_size", 1):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orthogonal change.

@armenzg armenzg marked this pull request as ready for review April 16, 2026 12:51
@armenzg armenzg requested review from a team as code owners April 16, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant